package main

import (
	"bufio"
	"fmt"
	"math/rand"
	"os"
	"strconv"
	"time"
)

var figures = [3]string{"rocker", "scissor", "paper"}

/**
0 > 1 , 1 > 2 , 2 > 0
*/
func main() {
	fingerGuess()
}

func fingerGuess() {
	inputReader := bufio.NewReader(os.Stdin)
	for {
		rand.Seed(time.Now().UnixNano())
		randInt := rand.Intn(3)
		figure := figures[randInt]
		fmt.Println("please input your figure, 0:rocker ; 1:scissor ; 2:paper")
		line, _, _ := inputReader.ReadLine()
		inputInt, _ := strconv.Atoi(string(line))
		if inputInt != 0 && inputInt != 1 && inputInt != 2 {
			fmt.Println("输入的数字错误")
			continue
		}
		result := compare(inputInt, randInt)
		if result == 1 {
			fmt.Println("你赢了，电脑出的是： " + figure)
		} else if result == -1 {
			fmt.Println("你输了，电脑出的是： " + figure)
		} else if result == 0 {
			fmt.Println("打和")
		}
	}
}

func compare(inputInt int, destInt int) int {
	// 0和 1赢 -1输
	if inputInt-destInt == -1 {
		return 1
	}
	if inputInt-destInt == 1 {
		return -1
	}
	if inputInt-destInt == 2 {
		return 1
	}
	if inputInt-destInt == -2 {
		return -1
	}
	return 0
}
